/*
 * @Author: quit
 * @Date: 2022-01-08 09:43:53
 * @LastEditTime: 2022-01-15 14:51:08
 * @Descripttion: 数据与组件映射,匹配.
 */
const ToPoMatch = {}

// 如果需要手动映射type和组件的关系，请在这里配置
ToPoMatch.viewRegisterMap = {
    triangle: 'view-triangle',
    rect: 'view-rect',
    circular: 'view-circular',
    line: 'view-line',
    'line-arrow': 'view-line-arrow',
    'chart-line': 'view-chart',
    'chart-line-step': 'view-chart',
    'chart-bar': 'view-chart',
    'chart-pie': 'view-chart-pie',
    'chart-gauge': 'view-chart-gauge',
    dashed: 'view-dashed'
}

// 优先匹配map，否则将自动匹配
ToPoMatch.parseViewName = function(component) {
    var viewName = ToPoMatch.viewRegisterMap[component.type]
    // console.log('viewName :', viewName, component.type)
    if (viewName === undefined) {
        // console.info(`没有手动配置组件映射，将根据数据的type自动匹配，当前组件类型=${component.type}`)
        viewName = 'view-' + component.type
    }
    return viewName
}

ToPoMatch.parseEchartType = function(component, option) {
    delete option.series[0]['step']
    delete option.series[0]['smooth']
    if (component.type === 'chart-line') {
        option.series[0].type = 'line'
        option.series[0]['smooth'] = true
    } else if (component.type === 'chart-bar') {
        option.series[0].type = 'bar'
    } else if (component.type === 'chart-line-step') {
        option.series[0].type = 'line'
        option.series[0].step = 'start'
    }
}

export default ToPoMatch
